package com.hsh.dao.impl;

import com.hsh.dao.AddFavorDao;
import com.hsh.dao.GetFavorDao;
import com.hsh.util.DruidUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class GetFavorDaoImpl extends DruidUtil implements GetFavorDao {
    @Override
    public int getFavorById(int bid) {
        int favor = 0;
        Connection conn = null;
        PreparedStatement state = null;
        ResultSet rs = null;
        try {
            conn = getConnection();
            //查询数据库中的点赞数favor
            String sql ="select favor from blog where bid=?";
            state = conn.prepareStatement(sql);
            state.setInt(1,bid);
            rs = state.executeQuery();
            while (rs.next()){
                favor = rs.getInt("favor");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            close(conn, state, null);
        }
        return favor;
    }
}
